<?php
class ControllerMyplanInformation extends Controller{
	public function index(){
	
		$this->load->model("myplan/user");
		
		$data=array();
		$data['user_id']=$this->user->getId();
		$this->data['infos']=$this->model_myplan_user->getAllInfo($data);
		$this->data['friendadd_requests']=$this->model_myplan_user->getAllFriendaddRequest($data);
		
		$this->data['action_handle']=$this->url->link("myplan/information/handlerequest")."&friend_id=";
		$this->data["action_checkinfo"]=$this->url->link("myplan/information/handlecheckinfo")."&info_id=";;
		
		if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/myplan/information.tpl')) 		            {
				$this->template = $this->config->get('config_template') . '/template/myplan/information.tpl';
			} else {
				$this->template = 'default/template/myplan/information.tpl';
			}
			
			$this->children = array(
			'myplancommon/footer',
			'myplancommon/header'
			);
											
			$this->response->setOutput($this->render());
	}	
	
	public function handlerequest(){
		
		if(isset($this->request->get['friend_id'])){
				$this->load->model("myplan/user");
				$data=array();
				$user_id=$this->user->getId();
				$friend_id=$this->request->get['friend_id'];
				$data['friend_id']=$friend_id;
				$data['user_id']=$user_id;
			if($this->request->get['handle']=='y'){
			
				$this->model_myplan_user->addToFriend($data);
				
				$data0=array();
				$data0['friend_id']=$user_id;
				$data0['user_id']=$friend_id;
				
				$this->model_myplan_user->addToFriend($data0);
				
				$this->model_myplan_user->deleteRequest($data);
				$this->session->data['success']="已经添加好友.";
			}else{
				$this->model_myplan_user->deleteRequest($data);
			}
			$this->redirect($this->url->link("myplan/information"));
		}
		
	}
	
	public function handlecheckinfo(){
		if(isset($this->request->get['info_id'])){
				$this->load->model("myplan/user");
				
				$info=$this->model_myplan_user->getInfoById($this->request->get['info_id']);
				
				$this->model_myplan_user->deleteInfoById($this->request->get['info_id']);
				
				if($info["info_type"]==1){
					
					$this->redirect($this->url->link("myplan/viewplan")."&".$info["params"]);
					
				}
				
		}
	}
	
	public function validate(){
		if($this->request->post["content"]==""){
			$this->data["warning"]="不能为空";
			return false;
		}
	    return true;
	}
}
?>
